#!/bin/sh
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

if [ -f /lib/firmware/brcm/brcmfmac43455-sdio.txt ] ; then
	rm -f /lib/firmware/brcm/brcmfmac43455-sdio.txt || true
	cp -v /lib/firmware/brcm/brcmfmac43455-sdio.beagleboard.org,am5729-beagleboneai.txt /lib/firmware/brcm/brcmfmac43455-sdio.txt
else
	cp -v /lib/firmware/brcm/brcmfmac43455-sdio.beagleboard.org,am5729-beagleboneai.txt /lib/firmware/brcm/brcmfmac43455-sdio.txt
fi

if [ -f /lib/firmware/brcm/brcmfmac43455.bin ] ; then
	rm -f /lib/firmware/brcm/brcmfmac43455.bin || true
	cp -v /lib/firmware/brcm/brcmfmac43455-sdio_am5729-beagleboneai.bin /lib/firmware/brcm/brcmfmac43455.bin
else
	cp -v /lib/firmware/brcm/brcmfmac43455-sdio_am5729-beagleboneai.bin /lib/firmware/brcm/brcmfmac43455.bin
fi

if [ -f /etc/udev/rules.d/90-bbai-virt-ap.rules ] ; then
	rm -f /etc/udev/rules.d/90-bbai-virt-ap.rules || true
fi

case "$1" in
	configure)
		systemctl enable bb-bbai-tether.service || true
		if [ -x /usr/sbin/update-initramfs -a -e /etc/initramfs-tools/initramfs.conf ] ; then
			update-initramfs -u
		fi
	;;

	abort-upgrade|abort-remove|abort-deconfigure)
	;;

	*)
		echo "postinst called with unknown argument \`$1'" >&2
		exit 1
	;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0

